package net.root.plain.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class DBConn {
	private static SQLiteDatabase db = null;
	public final static String db_name = "alarm.db";
	public final static String table_name = "alarm";
	/**
	 * columns = {"_no","alarmBell","alarmLabel","alarmRepeat","alarmTime","alarmStatus","alarmVibrate"};
	 * */
	public final static String[] columns = 
		{"_no","alarmBell","alarmLabel","alarmRepeat","alarmTime","alarmStatus","alarmVibrate"};

	public static SQLiteDatabase getConnection(Context context) {
		String sql;
		try {
			db = context.openOrCreateDatabase(db_name,
					SQLiteDatabase.CREATE_IF_NECESSARY, null);
			sql = "create table if not exists " + table_name + " ("
					+ "_no integer primary key,"
					+ "alarmBell text,"
					+ "alarmLabel text,"
					+ "alarmRepeat integer," 
					+ "alarmTime text,"
					+ "alarmStatus integer," 
					+ "alarmVibrate integer)";
			db.execSQL(sql);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return db;
	}

	public static void close() {
		if (db == null) {
			return;
		}
		try {
			if (db.isOpen()) {
				db.close();
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		db = null;
	}
}
